﻿using System;
using System.Linq;
using Shell.DomainDot;
using Framework.Poco;

namespace Framework.Domain
{
    /// <summary>
    /// 经销商文章更新器
    /// </summary>
    public class UpdateAgencyArticle : DomainDotBase<Agency>
    {
        /// <summary>
        /// 经销商的文章
        /// </summary>
        public WithMany<Article> Articles { get; set; }

        /// <summary>
        /// 更新经销商文章
        /// </summary>
        public void Update(Article instance)
        {
            var original = this.Articles.SingleOrDefault(i => i.Id.Equals(instance.Id));
            if (original == null)
            {
                return;
            }
            original.Name = instance.Name;
            original.Content = instance.Content;
            original.IsTopmost = instance.IsTopmost;
            this.Articles.Submit();
        }
    }
}
